﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace QLDHS
{
    public class Common
    {
        private static readonly string[] VietnameseSigns = new string[] {    
        "aAeEoOuUiIdDyY",
        "áàạảãâấầậẩẫăắằặẳẵ",
        "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
        "éèẹẻẽêếềệểễ",
        "ÉÈẸẺẼÊẾỀỆỂỄ",
        "óòọỏõôốồộổỗơớờợởỡ",
        "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
        "úùụủũưứừựửữ",
        "ÚÙỤỦŨƯỨỪỰỬỮ",
        "íìịỉĩ",
        "ÍÌỊỈĨ",
        "đ",
        "Đ",
        "ýỳỵỷỹ",
        "ÝỲỴỶỸ"
        };
        public static string RemoveSign4VietnameseString(string str)
        {
            for (int i = 1; i < VietnameseSigns.Length; i++)
            {
                for (int j = 0; j < VietnameseSigns[i].Length; j++)
                { str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]); }
            }
            return str;
        }

        public static DateTime ToDateTime(string input)
        {
            string temp = string.Empty;

            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] - 48 >= 0 &&
                    input[i] - 48 <= 9)
                { temp += input[i]; }
            }

            if (temp.Length < 8)
            { return DateTime.Now; }
            else
            {
                temp = temp.Substring(0, 8);
                return new DateTime(Convert.ToInt32(temp.Substring(4, 4)), Convert.ToInt32(temp.Substring(2, 2)), Convert.ToInt32(temp.Substring(0, 2)));
            }
        }

        public static bool IsNumeric(string input)
        {
            int output = 0;
            return int.TryParse(input, out output);
        }
        public static string ToNullSet0(string input)
        {
            if (Convert.ToInt32(input) == 0)
            {
                return null;
            }
            return input;
        }
      
    }
}
